package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.Sample;
import com.yiya.bean.SysUser;
import com.yiya.mapper.SampleMapper;
import com.yiya.model.SampleCplex;
import com.yiya.model.SampleCplexModel;

@Service("sampleService")
public class SampleService {
	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(SampleService.class);

	@Autowired
	private SampleMapper sampleMapper;

	public List<SampleCplex> queryByList(SampleCplexModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<SampleCplex> list = sampleMapper.selectByModel(bean);
		return list;
	}

	public int queryByCount(SampleCplexModel bean) {
		return sampleMapper.countByModel(bean);
	}

	public int add(Sample bean) {
		return sampleMapper.insert(bean);
	}

	public int Update(Sample bean) {
		return sampleMapper.updateByPrimaryKeySelective(bean);
	}

	public Sample queryById(Integer id) {
		return sampleMapper.selectByPrimaryKey(id);
	}

	public void delete(Integer[] ids, SysUser user) {
		Date nowTime = new Date();
		for (Integer id : ids) {
			Sample bean = sampleMapper.selectByPrimaryKey(id);
			bean.setUpdateBy(user.getId());
			bean.setUpdateTime(nowTime);
			bean.setDelFlag(1);
			sampleMapper.updateByPrimaryKeySelective(bean);
		}
	}
}
